class UserQuantPreferences:
    """用户量化分析偏好设置"""
    
    def __init__(self, user_manager):
        self.user_manager = user_manager
    
    def set_analyzer_preference(self, user_id, analyzer_type):
        """设置用户首选的量化分析框架"""
        if analyzer_type not in ['hikyuu', 'qlib']:
            raise ValueError(f"不支持的分析器类型: {analyzer_type}")
            
        return self.user_manager.update_user(
            user_id,
            {'preferred_analyzer': analyzer_type}
        )
    
    def get_analyzer_preference(self, user_id):
        """获取用户首选的量化分析框架"""
        user = self.user_manager.get_user(user_id)
        if not user:
            raise ValueError(f"用户不存在: {user_id}")
            
        return user.get('preferred_analyzer', 'hikyuu')  # 默认使用Hikyuu
    
    def set_backtest_period(self, user_id, period_days):
        """设置用户回测周期"""
        if not isinstance(period_days, int) or period_days <= 0:
            raise ValueError("回测周期必须是正整数")
            
        return self.user_manager.update_user(
            user_id,
            {'backtest_period_days': period_days}
        )
    
    def get_backtest_period(self, user_id):
        """获取用户回测周期"""
        user = self.user_manager.get_user(user_id)
        if not user:
            raise ValueError(f"用户不存在: {user_id}")
            
        return user.get('backtest_period_days', 365)  # 默认1年 